package com.example.bobo.yuejian322.MyImage;

import android.app.DialogFragment;
import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

import com.example.bobo.yuejian322.Activity.PeixunDetialActivity;
import com.example.bobo.yuejian322.Activity.UpdateMyActivity;
import com.example.bobo.yuejian322.R;


/**
 * A simple {@link Fragment} subclass.
 *
 */
public class ConsultDialog extends DialogFragment {
	Context context;
	Window win;
	int layoutID;
	View view;
	EditText name,pass;
	public ConsultDialog(Context context,int layoutId) {
		this.context=context;
		this.layoutID = layoutId;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// Inflate the layout for this fragment
		
		view = inflater.inflate(layoutID, container,
				false);

		 win = getDialog().getWindow();
		WindowManager.LayoutParams lp = win.getAttributes();

	    initialize();
		//透明度
		lp.alpha = 0.8f;
		win.setAttributes(lp);	




		return view;
	}
	private void initialize(){

		switch (layoutID){
			case  R.layout.dialog_consult:
				win.setGravity(Gravity.CENTER_HORIZONTAL| Gravity.BOTTOM);
				LinearLayout layout_tel = (LinearLayout) view.findViewById(R.id.layout_tel);
				layout_tel.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						//引用哪个类的哪个方法
						((PeixunDetialActivity) getActivity()).callPhone();
						ConsultDialog.this.dismiss();
					}

				});

				break;
			case  R.layout.dialog_pass:
				win.setGravity(Gravity.CENTER);
				Button btn = (Button) view.findViewById(R.id.btn_pass);
				pass= (EditText) view.findViewById(R.id.update_pass);
				btn.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						//引用哪个类的哪个方法
						((UpdateMyActivity) getActivity()).Pass(pass.getText().toString());
						ConsultDialog.this.dismiss();
					}

				});
				break;


			case  R.layout.dialog_name:
				win.setGravity(Gravity.CENTER);
				Button btn_name = (Button) view.findViewById(R.id.btn_name);
				 name = (EditText) view.findViewById(R.id.update_name);
				btn_name.setOnClickListener(new OnClickListener() {
					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						//引用哪个类的哪个方法
						((UpdateMyActivity) getActivity()).Name(name.getText().toString());
						ConsultDialog.this.dismiss();
					}

				});
				break;
			default:
				break;

		}

	}

}
